
var Web3= require('web3');
var config=require('./config');
var fs=require('fs');
var execSync =require('child_process').execSync;
var web3sync = require('./web3sync');
var BigNumber = require('bignumber.js');


if (typeof web3 !== 'undefined') {
	web3 = new Web3(web3.currentProvider);
} else {
	web3 = new Web3(new Web3.providers.HttpProvider(config.HttpProvider));
}

console.log(config);

var filename="TestPaillier";
var address=fs.readFileSync(config.Ouputpath+filename+'.address','utf-8');
var abi=JSON.parse(fs.readFileSync(config.Ouputpath/*+filename+".sol:"*/+filename+'.abi', 'utf-8'));

var contract = web3.eth.contract(abi);
var instance = contract.at(address);

async function sleep(timeout) {  
	return new Promise((resolve, reject) => {
			setTimeout(function() {
			resolve();
		}, timeout);
	});
}

(async function(){
	var put=instance.put();
	console.log("put="+put);

	var testsucceed = 0;
	var testerr = 0;
	
	var c1 = "0080B3659E936164926935376D4AA81FE1A8101B4A657EFF158C5215F3F85530D1906A4449546ABB8A6B4BA628DC5A4D0F5C3BFECE19ED4AA39C2CC8F7590F5755C186C80E26882BB7BEE4917CB2559F6C64747EBD592DEEA9195E2A5E9C5A7BD4A76FBC4432FE87EE1A6092B12B16F3AD2EE0C9269886FF72161A6DE0C2A0FC86194336F5AB1896A2A52388B2A11B21F6D877822E540997E4728C74594240760C0FD0F0EC22B6B52810CF7DB5F7B0416211451A497F5118FB7F72CA5CADA1FE15A67D8A14D8D5564244C62CF94C56874F0CC3210E75E0B2A543BDC02A8AE776D29FF005BC0774C0E103B5CE79E2D7C2CC9ABBA31A4938A0A490356F357DD7328AE924B957D16B8A2C1A43A0AB5E63C85BD345F822D0DB60F64A8505767F306FCBF5D52E49DA5174EEAAD983F447F1CDB3378DE9D3301804C4BD2C3B298B332CD45A59150311214000712472585C5D2CC266CFDFBFD7F3203948F8C36F3570EAAA53310840A45AA781DCF1156235111A0DC774660DE0F1C2CE396F4B0E14CFFBD0F3";
	var c2 = "0080B3659E936164926935376D4AA81FE1A8101B4A657EFF158C5215F3F85530D1906A4449546ABB8A6B4BA628DC5A4D0F5C3BFECE19ED4AA39C2CC8F7590F5755C186C80E26882BB7BEE4917CB2559F6C64747EBD592DEEA9195E2A5E9C5A7BD4A76FBC4432FE87EE1A6092B12B16F3AD2EE0C9269886FF72161A6DE0C2A0FC86196D2097E9608551A43770B3BD8AB822B1BB9E5987725DF9BBC401F14292755DA24030ACC69ADCA7EA9B2484AEA98EE7F73C703CE4E76CDC2EF85D749993E4DE088DFCCB626CB2FE6BDA3DBAE70108FCED4CF00A5945E6C04B87A58713A62DEABDA0E6E525C75E5415D90CB59BC72A522AC948E3A1B6ADF1891C8FE973B60776A9335D0FA05DC426ED7616A6F216C9586C3D10430E881F6834691C18BEAF054CE19777E33293A89915221C7D420DB0233CA775C6C4B5D260988F23DBDA09A3D66540FD47488EB919C1DED53561B427B54E5C63BF606DBB8F6242A39B1E697F3B0FF86A7AFCB0AA5E78A77CAA47D355730B19788A6F6E7EEEEAED8633622543179E";
	var c3 = "0080B3659E936164926935376D4AA81FE1A8101B4A657EFF158C5215F3F85530D1906A4449546ABB8A6B4BA628DC5A4D0F5C3BFECE19ED4AA39C2CC8F7590F5755C186C80E26882BB7BEE4917CB2559F6C64747EBD592DEEA9195E2A5E9C5A7BD4A76FBC4432FE87EE1A6092B12B16F3AD2EE0C9269886FF72161A6DE0C2A0FC8619679C04E3C5A73439B3BA5CAEFB666357912294740E6D0ABD4E5B78B2796BDAB158DA9A9ED0708EA41EDD4EB1B04B8F52E1FED7BC5EC568179A0102FC5D1A35C57AB899B86D1A93E90E12265A9395680BC7CEA47DBE07B61281548523F6A68C48BC580CDB6C26D18B7F144DE9CF9FF061AD616CE813C6232E4917835820CDC11FD59ED6A62B5E6AB297A12E782B3E8C639A3A1E68A1796E3E0449E02B4AE57869481579130FE95149B4B5238D0C9152781B810CBD85449E7EE049E4F556D4980D57751C80228D569A67B9B410C0DCAADD803513C341F354A58E04D7CACDF4F4013ABA0CD5BE3E9A14734D5BD6FE62CAD8A936E070B9337CCF5A11235F0FCE88DC";
		
	var result = instance.add(c1, c2);
	if(c3 === result){
		testsucceed++;
		console.log("test succeed result=", result, ",c3=", c3, ",c1=", c1, ",c2=", c2);
	}else{
		testerr++;
		console.log("test failed result=", result, ",c3=", c3, ",c1=", c1, ",c2=", c2);
	}
})()
